package me.zk.practice1.hw;

import java.util.Scanner;
import java.util.Stack;

public class HWBJJ34 {
    //a{b{d,e{g,h{,i}}},c{f}}
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String str = scanner.nextLine();
        TreeNode root = buildTree(str);
        StringBuilder sb = new StringBuilder();
        dfs(sb,root);
        System.out.println(sb);
    }
    public static TreeNode buildTree(String data) {
        Stack<TreeNode> stack = new Stack<>();
        TreeNode root = null;
        TreeNode current = null;
        int flag =0;

        for (String s : data.split("")) {
            switch (s){
                case "{":
                    //
                    if (current == null) {
                        return null;
                    }
                    stack.push(current);
                    flag = 1;
                    break;
                case ",":
                    //
                    flag = 2;
                    break;
                case "}":
                    stack.pop();

                    break;
                default:
                    current = new TreeNode(s);
                    if (root == null) {
                        root = current;
                    }
                    if (flag == 1) {
                        stack.peek().left = current;
                    } else if (flag == 2) {
                        stack.peek().right = current;
                    }
                    flag=0;

            }


        }

        return root;
    }





    public static void dfs(StringBuilder sb,TreeNode node){

        if (node == null) {
            return;
        }
        dfs(sb,node.left);
        sb.append(node.val);
        dfs(sb,node.right);

    }

    static class TreeNode{
        String val;
        TreeNode left;

        TreeNode right;

        public TreeNode(String val) {
            this.val = val;
        }
    }
}

